//判断浏览器
var navol,page;
function updateSkin(url){
	var updateUrl=getUpdate();
	var url=rot+"/manage/skin/update.do?url="+url+updateUrl;
	//var urls="http://u.ttpod.com/u?v=v1.2.0.2011022911,s=s200,uid=60c4eb29b6be8a6757883ce9d424ea407fb6c74e,mid=iTouch4,f=f0,imsi=,hid=77399C661FFD,splus=5.0.1,active=0";
	//var url=rot+"/manage/skin/update.do?url="+urls;
	AjaxRequest(url,function(rs){
		location.href=encodeURI(rs);
		closeDiv();
	});
}
//获得每个小时的时间戳
function getHours(){
	var date=new Date();  
	return date.getHours();
}
this.toRequest=function(succ){
	//表示正在加载    
	$("olList").setAttribute("data-load","true");
	//获得页面上的page的值
	page=parseInt($('page').innerHTML);
	var url=rot+"/manage/skin/more.do?channelId="+channelId+"&p="+page+"&tt_time=ttpod_"+getHours();
	AjaxRequest(url,function(rs){
		try{
			rs=eval('('+rs+')');
			var olList=$("olList");
			var li="";
			var count=$("count").value;
			var index;
			for(var i=0;i<rs.softDTOList.length;i++){
				if(count%2==0){
					index=(page-1)*count+i;
				}else{
					index=(page-1)*count+i+1;
				}
				//偶行和奇行的背景色
				var backgroundColor = index%2==0 ? "#e1e1e1" : "#f0f0f0";
				var downA="";
				if(rs.softDTOList[i].isNew == 1){
					downA = "<a href='javascript: ;'  onclick=\"logAndGo('skin',{'type':'down','chid':4,'adid':'"+rs.softDTOList[i].adId+"','ds':1},'"+rs.softDTOList[i].netDownUrl+"?skinid="+rs.softDTOList[i].adId+"');\">下载</a>"
				}else{
					downA = '<a class="orange" href="javascript: ;" onclick="openDiv();">下载</a>';
				}
				li+="<li style='background-color:"+backgroundColor+";'><a href='javascript: ;' " +
				"onclick=\"logAndGo('skin',{'type':'detail','chid':4,'adid':'"+rs.softDTOList[i].adId+"'},'"+rot+"/manage/skin/detail/"+rs.softDTOList[i].id+".do?isNew="+rs.softDTOList[i].isNew+"');\"> <aside>"+
				"<img xSrc='"+picctx+"/"+rs.softDTOList[i].recommendPicUrl+"' src='"+root+"/style/sicobg.jpg' /></aside> <figure>"+
				"<h1>"+rs.softDTOList[i].recommendName+"</h1>适用版本："+rs.softDTOList[i].version+"<br>分类："+rs.softDTOList[i].classify+
				"<br>作者："+rs.softDTOList[i].author+"</figure> </a><q> "+downA+" <br>"+
				"大小:"+rs.softDTOList[i].size+"<b class='start"+rs.softDTOList[i].level+"'></b></q></li>";
            }
            var olElement=document.createElement("ol");
            olElement.innerHTML=li;
			olList.appendChild(olElement);
			succ();
			var allpage=$("allpage").value;
			if(page>=allpage){
				$("loading").style.display="none";
			}
			page++;
			$('page').innerHTML=page;
			//让他可以继续滚动加载
			$("olList").setAttribute("data-load","false");
		}catch(err){
			$("loadId").innerHTML="加载失败！";
		}
	});
};
//滚动加载
var scrollTop=0;
window.onscroll=function(){
	//垂直方向滚动的值 document.documentElement.scrollTop
	//网页可见区域高 document.body.clientHeight
	//可见区域高 document.documentElement.clientHeight
	//网页被卷去的高 document.body.scrollTop
	//取窗口滚动条高度
    if(document.documentElement&&document.documentElement.scrollTop){   
        scrollTop=document.documentElement.scrollTop;   
    }else if(document.body){   
        scrollTop=document.body.scrollTop;   
    }
	//取窗口可视范围的高度 
    var clientHeight=0;   
    if(document.body.clientHeight&&document.documentElement.clientHeight){   
        clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;           
    }else{   
        clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;       
    }
    var ScrollHeight=0;
	//取文档内容实际高度 
    ScrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);   
	if(scrollTop+clientHeight>=ScrollHeight-50){
		var allpage=$("allpage").value;
		if($("olList").getAttribute("data-load")=="false"){
			if(page>allpage){
				$("loading").style.display="none";
			}else{
				toRequest(function(){
					scrollLoad();
				});
			}
		}
	}
	scrollLoad();
};

window.onload=function(){
	window.scrollTo(1,1);
	page=parseInt($('page').innerHTML);
    scrollLoad();
    navol=$("navgitor");
   // _style(navol,clientSize);
}
 
 //点击导航切换
 function setStyle(nav,url,id){
 	 if(id==44){
		 	window.location.href=url+"&f="+f+"&v="+v+"&imsi="+imsi+"&nav="+nav+"&s="+s+"&splus="+splus+"&mid="+mid+"&net="+net+"&uid="+uid+"&active="+active+"&rom="+rom;
	 }else if(id==4){
		 	window.location.href=url+"&f="+f+"&v="+v+"&imsi="+imsi+"&nav="+nav+"&s="+s+"&splus="+splus+"&mid="+mid+"&net="+net+"&uid="+uid+"&active="+active+"&rom="+rom;
	 }else{
		 	window.location.href=url;
	 }
 }
//打开弹层
var oldScrollTop=0;
function openDiv(){
	oldScrollTop=scrollTop;
	$("bodyId").style.overflow="hidden";
	var bodydiv=$("divLayer");
	bodydiv.style.position = "fixed";
	bodydiv.style.display="";
	bodydiv.style.width = "100%";
	bodydiv.style.height = (Math.max(document.body.scrollHeight,document.documentElement.scrollHeight))+"px";
	bodydiv.style.zIndex = 98;
	bodydiv.style.top = 0;
	bodydiv.style.left = 0;
	var s=$("openId");
	s.style.border = "1px solid #ccc";
	s.style.background = "#fff";
	s.style.zIndex = 99;
}
//关闭弹层
function closeDiv(){
	setTimeout(function(){
		$("bodyId").style.overflow="auto";
		$("bodyId").scrollTop=oldScrollTop;
		$("divLayer").style.display="none"
	},600);
}